using UnityEngine;
using UnityEngine.EventSystems;

public class GUIItemUse : MonoBehaviour, IPointerClickHandler, IEventSystemHandler
{
	public GUIItemCollector guiitem;

	public GameObject DropBT;

	private void Start()
	{
		if (guiitem == null)
		{
			guiitem = GetComponent<GUIItemCollector>();
		}
		if ((bool)DropBT)
		{
			DropBT.SetActive(guiitem.Type != "Ground");
		}
	}

	public void Use()
	{
		if (!(guiitem == null))
		{
			if (guiitem.Type == "Ground" && UnitZ.playerManager != null && UnitZ.playerManager.PlayingCharacter != null && guiitem.Item != null && guiitem.Item.Item != null)
			{
				UnitZ.playerManager.PlayingCharacter.Interactive(guiitem.Item.Item.gameObject);
			}
			if (guiitem.Type == "Inventory" && guiitem.currentInventory != null && guiitem.Item != null)
			{
				guiitem.currentInventory.EquipItemByCollector(guiitem.Item);
			}
		}
	}

	public void DropToGround()
	{
		if (guiitem.Type == "Inventory" && guiitem.Item != null)
		{
			guiitem.currentInventory.DropItemByCollector(guiitem.Item, guiitem.Item.Num);
		}
	}

	public void OnPointerClick(PointerEventData eventData)
	{
		if (eventData.button == PointerEventData.InputButton.Right)
		{
			Use();
		}
	}
}
